using System;
using System.Data;
using System.Xml;

using OR.Reuse.Persistence;

using Derived = OR.Lazarus.Business.Entities.Config;

namespace OR.Lazarus.Business.Entities.Config.Lazarus
{
	/// <summary>
	/// Defines an XSL Transform to apply, as well as a context for the transform and file generation parameters.
	/// </summary>
   public class TransformDetail : EntityBase
   {
		protected System.String mName;
		protected string mType;
		protected string mOutputType;
		protected string mSource;
		protected string mPrefix;
		protected string mSuffix;
		protected string mOutput;
		protected string mFolder;
		protected string mFilter;
		protected string mOverwrite;
		protected string mDescription;

		public TransformDetail()
		{
	
		}
	
		/// <summary>
		/// 
		/// </summary>
		public System.String Name
		{
			get
			{
				return ( mName );
			}
			set
			{
				mName = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Type
		{
			get
			{
				return ( mType );
			}
			set
			{
				mType = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string OutputType
		{
			get
			{
				return ( mOutputType );
			}
			set
			{
				mOutputType = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Source
		{
			get
			{
				return ( mSource );
			}
			set
			{
				mSource = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Prefix
		{
			get
			{
				return ( mPrefix );
			}
			set
			{
				mPrefix = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Suffix
		{
			get
			{
				return ( mSuffix );
			}
			set
			{
				mSuffix = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Output
		{
			get
			{
				return ( mOutput );
			}
			set
			{
				mOutput = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Folder
		{
			get
			{
				return ( mFolder );
			}
			set
			{
				mFolder = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Filter
		{
			get
			{
				return ( mFilter );
			}
			set
			{
				mFilter = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Overwrite
		{
			get
			{
				return ( mOverwrite );
			}
			set
			{
				mOverwrite = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public string Description
		{
			get
			{
				return ( mDescription );
			}
			set
			{
				mDescription = value;
			}
		}

		public override void LoadXml( XmlElement pSource )
		{
			// Scalar Values
			mName = DataUtility.GetString( pSource, "name" );
			mType = DataUtility.GetString( pSource, "type" );
			mOutputType = DataUtility.GetString( pSource, "output-type" );
			mSource = DataUtility.GetString( pSource, "source" );
			mPrefix = DataUtility.GetString( pSource, "prefix" );
			mSuffix = DataUtility.GetString( pSource, "suffix" );
			mOutput = DataUtility.GetString( pSource, "output" );
			mFolder = DataUtility.GetString( pSource, "folder" );
			mFilter = DataUtility.GetString( pSource, "filter" );
			mOverwrite = DataUtility.GetString( pSource, "overwrite" );
			XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lcfg:description", PersistenceConfig.Namespaces );
			
			if ( vDescription != null )
			{
				mDescription = vDescription.InnerText;
			}
			
		}
		
		public override XmlElement SaveXml( XmlDocument p_docContext )
		{
			XmlElement vNewElement	= p_docContext.CreateElement( "lcfg", "transform", "http://schemas.icitadel.com/Lazarus/Config.xsd" );

			// Scalar Values
			if ( !String.IsNullOrEmpty( mName ) )
			{
				vNewElement.SetAttribute( "name", mName );
			}
					
			if ( !String.IsNullOrEmpty( mType ) )
			{
				vNewElement.SetAttribute( "type", mType );
			}
					
			if ( !String.IsNullOrEmpty( mOutputType ) )
			{
				vNewElement.SetAttribute( "output-type", mOutputType );
			}
					
			if ( !String.IsNullOrEmpty( mSource ) )
			{
				vNewElement.SetAttribute( "source", mSource );
			}
					
			if ( !String.IsNullOrEmpty( mPrefix ) )
			{
				vNewElement.SetAttribute( "prefix", mPrefix );
			}
					
			if ( !String.IsNullOrEmpty( mSuffix ) )
			{
				vNewElement.SetAttribute( "suffix", mSuffix );
			}
					
			if ( !String.IsNullOrEmpty( mOutput ) )
			{
				vNewElement.SetAttribute( "output", mOutput );
			}
					
			if ( !String.IsNullOrEmpty( mFolder ) )
			{
				vNewElement.SetAttribute( "folder", mFolder );
			}
					
			if ( !String.IsNullOrEmpty( mFilter ) )
			{
				vNewElement.SetAttribute( "filter", mFilter );
			}
					
			if ( !String.IsNullOrEmpty( mOverwrite ) )
			{
				vNewElement.SetAttribute( "overwrite", mOverwrite );
			}
					
			if ( !String.IsNullOrEmpty( mDescription ) )
			{
				XmlElement	vDescription = p_docContext.CreateElement( "lcfg", "description", "http://schemas.icitadel.com/Lazarus/Config.xsd" );
				vDescription.InnerText = mDescription;
				vNewElement.AppendChild( vDescription );
			}
					

			return ( vNewElement );
		}

		public virtual object Clone()
		{
			Derived.TransformDetail v_oReturn = new Derived.TransformDetail();
			
			v_oReturn.Name = mName;
			v_oReturn.Type = mType;
			v_oReturn.OutputType = mOutputType;
			v_oReturn.Source = mSource;
			v_oReturn.Prefix = mPrefix;
			v_oReturn.Suffix = mSuffix;
			v_oReturn.Output = mOutput;
			v_oReturn.Folder = mFolder;
			v_oReturn.Filter = mFilter;
			v_oReturn.Overwrite = mOverwrite;
			v_oReturn.Description = mDescription;
			
			// FK Values

			// Collections
			
			return ( v_oReturn );
		}

		public virtual Derived.TransformDetail CloneTyped()
		{
			return ( ( Derived.TransformDetail )this.Clone() );
		}
   }
}
   